angular.module('starter.controllers', [])
/**
 * --2016/4/12--nomad
 * move wap controllers to here
 */
//main.js start
    .controller('MainCtrl', function ($interval, $scope, $ionicSlideBoxDelegate, $http, $rootScope, $q, $location, $stateParams, $state, $ionicConfig, $faUser, $faMAP, $faAPI, $faModal, $faPopup, $faUtil, $faIOSBridge, $faPlatform, $faWechat, $timeout, $ionicPopup, $filter) {
        if (window.localStorage.getItem("startpage") == "seen") {
            //判断是否已经展示过启动页，如果未展示过则跳转APP引导页
            $state.go('shopHome');
            return;
        }
        $scope.login = function(){
            $rootScope.modal.login(function () {

                //登录回调
                $faUtil.localStorage('user', $faUser.info);
                $faUser.info.isLogin = true;

                if($location.path()=='/') {
                    $state.go('shopHome');
                } else {
                    $state.reload();
                }

                window.localStorage.setItem("startpage", "seen");
            });
        }

        $scope.zhuce = function() {
            $rootScope.modal.register();
        }
        //
        //////7-15私募基金法更改
        ////if (!$faUser.info.isLogin) {
        ////  $rootScope.modal.login();
        ////}
        //// wap3Ctrl merge MainCtrl
        //$faAPI.user.status().then(function (json) {
        //    $faUser.checkStatus(json);
        //});
        //
        //$rootScope.platform = $faPlatform;
        ////首页banner
        //$scope.homeBanner;
        //
        //// 推荐
        //$scope.recommend = [];
        //// 推荐产品链接
        //$scope.recPro;
        //// 超级头条
        //$scope.superList;
        //
        //var h1, h2;
        //// 邀请人账号和媒体来源统计
        //var srcID = $stateParams.inviteId;
        //
        //var reg = /^[0-9]+$/;
        //if (reg.test(srcID) && srcID) {
        //    var data = {
        //        src: srcID
        //    };
        //
        //    $faAPI.publicnom.ad(data).then(function () {
        //    });
        //    $rootScope.srcID = srcID;
        //    $scope.modal.register();
        //}
        //
        //
        //$scope.goUrlInfo = function (url) {
        //    goUrlInfo(url);
        //};
        //
        //
        //function getRecProUrl(type) {
        //    if (type == '06') {
        //        return 'pevc'
        //    } else {
        //        return 'detail'
        //    }
        //
        //}
        //
        //// 首页banner
        //$faAPI.wap3.homeBanner({
        //    m: 15
        //}).then(function (json) {
        //    $scope.homeBanner = json.list || [];
        //
        //});
        ////消息统计
        //
        //$rootScope.ddzt = {};
        //$faAPI.inform.ddtz().then(function (json) {
        //    $rootScope.ddzt = json;
        //});
        //var lyTimer = $interval(function () {
        //    $faAPI.inform.ddtz().then(function (json) {
        //        $rootScope.ddzt = json;
        //    });
        //
        //}, 30000);
        //
        //
        ////活动推荐和链接
        //$faAPI.home.advertList({
        //    m: '21'
        //}).then(function (json) {
        //    $scope.recommend = json.list || [];
        //
        //});
        //
        //// 超级头条
        //$faAPI.wap3.homeBanner({
        //    m: '14'
        //}).then(function (json) {
        //    $scope.superList = json.list || [];
        //
        //    if ($scope.superList) {
        //
        //        var s = document.getElementById('superList');
        //        if (!s) {
        //            return
        //        }
        //
        //        var h = 0;
        //
        //        $interval(function () {
        //            s.style.webkitTransform = 'translateY(-' + h + '00%)';
        //
        //            h++;
        //            if (h == $scope.superList.length) {
        //                h = 0;
        //            }
        //
        //        }, 3000);
        //
        //    }
        //
        //});
        ////认证提示信息
        //var hint = document.getElementById('homeHint');
        //$timeout(function () {
        //    hint.style.height = '0';
        //    hint.style.transition = 'height 1s linear';
        //
        //}, 10000);
        //
        ////延迟执行是为了新用户使用时，此弹出层出现在合格投资者认证弹窗之后
        ////$timeout(function(){
        ////
        ////  var hintv = document.getElementById('hintVideo');
        ////  //2016/11/11视频引导
        ////  if(!window.localStorage.ishintVideo){
        ////    hintv.style.display = 'block';
        ////  }
        ////},1000);
        //
        ////$timeout.cancel(loading);
        //
        //
        ////用于其他地方登录后更新产品列表的登录认证状态--2016/11/28
        //window.isprolistUpdate = function () {
        //    window.location.reload();
        //};
        //
        //
        //function getRecommentProduct() {
        //    //热门产品-recommentType=1首页热销产品  recommentType=3 产品列表推荐 recommentType=2 首页推荐
        //    $faAPI.customer.recommentProduct({
        //        recommentType: '1'
        //    }).then(function (json) {
        //        h1 = json.list.map(function (item) {
        //            if (item.fpFundInfoDTO) {
        //                item.fpFundInfoDTO.lsjzJson = item.fpFundInfoDTO.lsjzJson ? $faUtil.fromJson((item.fpFundInfoDTO.lsjzJson).replace(/“/g, '"')) : '';
        //            } else if (item.productDTO) {
        //                if (item.productDTO.expectSaleAmount != 0) {
        //                    item.productDTO.process = ((item.productDTO.allSubscriptionAmount * 100 / item.productDTO.expectSaleAmount).toFixed(2) > 100) ?
        //                        100 :
        //                        (item.productDTO.allSubscriptionAmount * 100 / item.productDTO.expectSaleAmount).toFixed(2);
        //                } else {
        //                    item.productDTO.process = 0;
        //                }
        //            }
        //            return item;
        //        });
        //
        //        h1 = h1.slice(0, 2);
        //        $scope.hotList = h1;
        //
        //        $scope.hotListfyFlag = json.fyFlag || '';
        //
        //    });
        //
        //    //首页最新推荐
        //    $faAPI.customer.recommentProduct({
        //        recommentType: '2'
        //    }).then(function (json) {
        //        h2 = json.list.map(function (item) {
        //            if (item.fpFundInfoDTO) {
        //                item.fpFundInfoDTO.lsjzJson = item.fpFundInfoDTO.lsjzJson ? $faUtil.fromJson((item.fpFundInfoDTO.lsjzJson).replace(/“/g, '"')) : '';
        //            } else if (item.productDTO) {
        //                if (item.productDTO.expectSaleAmount != 0) {
        //                    item.productDTO.process = ((item.productDTO.allSubscriptionAmount * 100 / item.productDTO.expectSaleAmount).toFixed(2) > 100) ?
        //                        100 :
        //                        (item.productDTO.allSubscriptionAmount * 100 / item.productDTO.expectSaleAmount).toFixed(2);
        //                } else {
        //                    item.productDTO.process = 0;
        //                }
        //            }
        //            return item;
        //        });
        //        h2 = h2.slice(0, 2);
        //        $scope.hotList2 = h2;
        //        $scope.hotList2fyFlag2 = json.fyFlag || '';
        //
        //    });
        //}
        //
        //getRecommentProduct();
        ////要做全局的登陆认证状态监听更新数据
        //$scope.$watch('userRole', function (newValue) {
        //    if (newValue) {
        //        getRecommentProduct()
        //    }
        //});
        //
        //$scope.goProList = function (id) {
        //    $rootScope.sletype = id;
        //    $state.go('product.prolist');
        //};
        //
        //
        ///**
        // * [agreement]
        // */
        //$faModal('agreement', 'views/common/agreement.html', $rootScope);
        //
        ///**
        // * [forget password]
        // */
        //$faModal('forgetPassword', 'views/common/forget.html', $rootScope, {
        //    step: 1,
        //    interval: 90,
        //    time: (new Date()).getTime(),
        //    sendTimer: '',
        //    initialize: function () {
        //        var self = this;
        //
        //        $interval.cancel(self.sendTimer);
        //
        //        self.data = {
        //            _pt: 'wap',
        //            agree: true,
        //        };
        //
        //        self.interval = 0;
        //        self.step = 1;
        //        self.isShowPassword = false;
        //        self.title = '找回密码';
        //    },
        //    showLogin: function () {
        //        var self = this;
        //        if ($scope.login && $scope.login.modal) {
        //            self.hide();
        //        }
        //        $rootScope.modal.login();
        //    },
        //    reset: function () {
        //        this.time = (new Date()).getTime();
        //    },
        //    sendVcode: function () {
        //        var self = this;
        //        var _data = this.data;
        //        if (!self.data.mobile) {
        //            $faPopup.alert({
        //                title: '未填写手机号码'
        //            });
        //        } else if (!/^1\d{10}$/.test(self.data.mobile)) {
        //            $faPopup.alert({
        //                title: ' 手机号码格式错误'
        //            });
        //        } else {
        //            self.interval = 90;
        //            $faAPI.media.sendLoginVcode(_data).then(function () {
        //                $interval.cancel(self.sendTimer);
        //
        //                self.sendTimer = $interval(function () {
        //                    if (self.interval > 0) {
        //                        self.interval--;
        //                    } else {
        //                        $interval.cancel(self.sendTimer);
        //                        self.interval = 0;
        //                    }
        //                }, 1000);
        //            });
        //        }
        //    },
        //    nextStep: function () {
        //        var self = this;
        //        if (!self.data.mobile) {
        //            $faPopup.alert({
        //                title: '未填写手机号码'
        //            });
        //        } else if (!/^1\d{10}$/.test(self.data.mobile)) {
        //            $faPopup.alert({
        //                title: ' 手机号码格式错误'
        //            });
        //        } else if (!self.data.smsCode) {
        //            $faPopup.alert({
        //                title: '未填写短信验证码'
        //            });
        //        } else {
        //            // self.sendVcode();
        //            self.step = 2;
        //            self.title = '设置新密码';
        //        }
        //    },
        //    done: function () {
        //
        //        var self = this;
        //
        //        // if (!self.data.mobile || !self.data.verifyCode) {
        //        //   self.init();
        //        //   self.step = 1;
        //        // } else if (!self.data.vCode) {
        //        //   $faPopup.alert({
        //        //     title: '未填写短信验证码'
        //        //   });
        //        // } else if (!self.data.confirmPassword) {
        //        //   $faPopup.alert({
        //        //     title: '未填写重置密码'
        //        //   });
        //        // } else
        //        if (!/^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,18}$/.test(self.data.confirmPassword)) {
        //            $faPopup.alert({
        //                title: '密码格式有误'
        //            });
        //        } else if (self.data.confirmPassword.length < 6 || self.data.confirmPassword.length > 18) {
        //            $faPopup.alert({
        //                title: '密码长度应在6-18位之间'
        //            });
        //        } else if (self.data.confirmPassword != self.data.confirmPassword2) {
        //            $faPopup.alert({
        //                title: '两次密码输入不一致！'
        //            });
        //        } else {
        //
        //            $faAPI.user.forgetLoginPwd(self.data).then(function (json) {
        //
        //                $faPopup.alert({
        //                    title: '密码重置成功'
        //                });
        //
        //                self.hide();
        //            });
        //        }
        //    }
        //});
        //
        ////线下活动
        //$scope.$on("$ionicView.enter", function () {
        //    //页面启动缓存时,其controller中不会反复执行，但会执行此监听-
        //    $faAPI.events.activity({
        //        "pageNo": 1,
        //        "pageSize": 1
        //    }).then(function (resp) {
        //        $scope.aclists = resp.list[0];
        //        $scope.aclists.activitiesImageUri = reqUrl + $scope.aclists.activitiesImageUri;
        //
        //    });
        //
        //});
        //
        //$scope.activityIsIng = function (activity) {
        //    activity = activity || {};
        //    return !($scope.activityIsFull(activity) || $scope.activityIsEnd(activity) || $scope.signUpIsEnd(activity));
        //};
        //$scope.signUpIsEnd = function (activity) {
        //    try {
        //        var now = $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss");
        //        return now > activity.activitiesRegistEndTime;
        //    } catch (err) {
        //    }
        //};
        //$scope.activityIsEnd = function (activity) {
        //    try {
        //        var nows = $filter('date')(new Date(), "yyyy-MM-dd HH:mm:ss");
        //        return nows > activity.activitiesEndTime;
        //    } catch (err) {
        //    }
        //};
        //$scope.activityIsFull = function (activity) {
        //    activity = activity || {};
        //    return activity.activitiesTotalPerson <= activity.activitiesParticipatePerson;
        //};
        ///**
        // * [$stateChangeStart]
        // */
        //$scope.goCustomer = function () {
        //    $faUser.info.isLogin ? $state.go('app.customer') : $rootScope.modal.login();
        //};
        //
        //$scope.goUserCenter = function () {
        //
        //    $faUser.info.isLogin ? $state.go('user') : $rootScope.modal.login();
        //};
        //
        ////ionic.Platform.ready(function() {
        ////  if(!$faUser.info.isLogin){
        ////    $rootScope.modal.login();
        ////  }
        ////});
        //
        //$scope.goCertification = function ($event) {
        //    $event.stopPropagation();
        //    $faUser.info.isLogin ? $state.go('app.myself.certification') : $rootScope.modal.login();
        //};
        //$scope.goInform = function () {
        //
        //    //$faUser.info.isLogin ? $state.go('inform') : $rootScope.modal.login();
        //    $state.go('inform');
        //};
        //$scope.goSearch = function () {
        //    $state.go('search');
        //};
        //
        //$scope.goUpload = function () {
        //    var popTitle = '';
        //    var popButton = '';
        //    if (!$faUser.info.isLogin) {
        //        // 要登录
        //        $rootScope.modal.login();
        //    } else if ($faUser.isCertEmpty()) {
        //        popTitle = '您还未上传名片，上传并审核通过后才能上传产品';
        //        popButton = '去上传';
        //        pop();
        //    } else if ($faUser.isCertIng()) {
        //        popTitle = '您的名片还在审核中，审核通过后才能上传产品';
        //        popButton = '看名片';
        //        pop();
        //    } else if ($faUser.isCertDeny()) {
        //        popTitle = '您的名片审核失败，请重新上传';
        //        popButton = '去上传';
        //        pop();
        //    } else {
        //        $state.go('app.upload');
        //    }
        //
        //    function pop() {
        //        var myPopup = $ionicPopup.show({
        //            title: popTitle,
        //            scope: $scope,
        //            buttons: [
        //                {
        //                    text: '取消',
        //                    type: 'confirmLoginCancel',
        //                    onTap: function (e) {
        //                        $state.go('app');
        //                    }
        //                },
        //                {
        //                    text: popButton,
        //                    type: 'button-positive confirmLogin',
        //                    onTap: function (e) {
        //                        $state.go('app.myself.certification', {repage: 'app.upload'});
        //                    }
        //                }
        //            ]
        //        });
        //    }
        //}
    })

    .controller('DownloadCtrl', function($scope, $timeout, $ionicNavBarDelegate,$faPlatform) {

  $timeout(function() {
    $ionicNavBarDelegate.showBar(false);
  }, 0);

})

.controller("register",["$scope, $faAPI",function($scope, $faAPI){
//	$scope.userShow = true
}])

.controller('wap3SearchCtrl', function($scope, $faUser,$rootScope,$stateParams,$faAPI,$faUtil,$faMAP,$state, $timeout, $ionicHistory, $location,$faPopup) {
  $scope.pShortName;
  $scope.hisList = {};
  var hisSearch = '';
  $scope.searchList = {};
  var ptyleList;
  if($stateParams.typelist){
    ptyleList = $stateParams.typelist;
    $scope.isAddSerch = true;
  }else {
    ptyleList = '';
    $scope.isAddSerch = false;
  }

  //document.addEventListener('touchstart',function(e){
  //  e.preventDefault();
  //  console.log('touched!');
  //  document.getElementById('txtSearch').focus();
  //});
  //var el = document.getElementById('txtSearch');
  //el.addEventListener('click',function(){
  //  console.log('觸發了方法');
  //  document.getElementById('txtSearch').focus();
  //});

  $scope.goCertification = function($event){
    $event.stopPropagation();
    $faUser.info.isLogin ? $state.go('app.myself.certification') : $rootScope.modal.login();
    $scope.$watch('userRole',function(newValue){
      //必须在此处初始化监听登录，否则会引发在其他地方登录了，导致此处监听错误。
      //表现为一进列表页会立即执行监听中的方法
      if(newValue){
        $scope.doingSearch();
      }
    });
  };

  $scope.page = {
    pageSize:10,
    pageNo:1,
    hasNaxtPage: false
  };
  $scope.product = {
    investType: $faMAP.investType,

  };
  $scope.notSearch = false;

  $scope.searchRecommend = {};
  $faAPI.product.recommendList({recommentType: 2}).then(function(json){
    if(json){
      $scope.searchRecommend = json.list[0];
    }
  });
  $faAPI.wap3.recPro({size: 4}).then(function(json){
    if(json.list){
      $scope.hotSearch = json.list || [];
      console.log($scope.hotSearch);
    }
  });
  $scope.productAddToShop = function (pt, product) {
    console.log('productAddToShop');
    if (product && pt) {
      var param = {productType: pt};
      if (pt != '01') {
        param.productId = product.code;
      } else {
        param.productId = product.id;
      }

      if (product.flagShop && product.flagShop == 'true') {
        $faPopup.confirm({
          title: '确定删除该产品？',
          cancelText: '取消',
          okText: '确定'
        }, function (res) {
          if (res) {
            $faAPI.shops.productDeleteToShops(param).then(function (json) {
              if (json) {
                if (!json.statusCode) {
                  /* $faPopup.alert({
                   title: '删除成功'
                   });*/
                  product.flagShop = '';
                }
              }
            });
          }
        });

      } else {
        $faAPI.shops.productAddToShops(param).then(function (json) {
          if (json) {
            if (!json.statusCode) {
              $faPopup.alert({
                title: '添加成功'
              });
              product.flagShop = 'true';
            }
          }
        });
      }
    }
  };


  function getHisList(){
    hisSearch = $faUtil.cookie('hisSearch');

    if(hisSearch){
      $scope.hisList = hisSearch.split(',').reverse().slice(0,3);
      $scope.hisList = unique2($scope.hisList);
    }else{
      $scope.hisList = {};
    }
  }

  getHisList();

  $scope.hisCommit = function(str){
    $scope.done(str);
  };

  $scope.resets = function(){
    $scope.pShortName = '';
  };

  $scope.clearHistory = function(){
    $faUtil.cookie.remove('hisSearch', {path: '/' });

    $timeout(function(){
      getHisList();
    }, 100);
  };

  $scope.isShowHis = true;
  $scope.doingSearch = function(str){
    if(str){
      $scope.pShortName = str;
    }
    if(!$scope.pShortName){
      $scope.pShortName = $scope.searchRecommend.productDTO.name;
    }

    if($scope.pShortName){
      $scope.page = {
        pageSize:10,
        pageNo:1,
        hasNaxtPage: true
      };

      if(hisSearch){
        hisSearch += ','+ $scope.pShortName;
      }else{
        hisSearch = $scope.pShortName;
      }
      $faUtil.cookie('hisSearch', hisSearch, {
        path: '/',
        expires: 1296000
      });

      var searchInput = document.getElementById("txtSearch");
      //searchInput.blur();

      $faAPI.product.allProductListN({pShortName: $scope.pShortName || '',
        pageNo: $scope.page.pageNo,
        pageSize: 10,
        pTypeList:ptyleList,
        flagShopQuery:true
      }).then(function(json){
        if(json){
          $scope.searchList = json.prodcutList;

          angular.forEach($scope.searchList, function(o){
            if(o.expectSaleAmount != 0){
              o.process = ((o.allSubscriptionAmount * 100 / o.expectSaleAmount).toFixed(2) > 100) ? 100 : (o.allSubscriptionAmount * 100 / o.expectSaleAmount).toFixed(2);
            }else{
              o.process = 0;
            }
            if(o.fpFundInfoDTO && o.fpFundInfoDTO.lsjzJson){
              o.fpFundInfoDTO.lsjzJson = angular.fromJson(o.fpFundInfoDTO.lsjzJson);

              console.log(o.fpFundInfoDTO.lsjzJson);
            }
          });

          $scope.isShowHis = false;
          $scope.page = json.page;
        }
      });

      getHisList();
    }
  };

  $scope.loadMore = function() {
    if($scope.pShortName && $scope.pShortName.length > 0){
      $scope.page.pageNo++;
      $faAPI.product.allProductListN({pShortName: $scope.pShortName || '',
        pageNo: $scope.page.pageNo,
        pageSize: 10,
        pTypeList:ptyleList,
        flagShopQuery:true
      }).then(function(json){
        if(json){
          if($scope.searchList && $scope.searchList.length >= 1){
            $scope.searchList = $scope.searchList.concat(json.prodcutList);
          }else{
            $scope.searchList = json.prodcutList;
          }

          angular.forEach($scope.searchList, function(o){
            if(o.expectSaleAmount != 0){
              o.process = ((o.allSubscriptionAmount * 100 / o.expectSaleAmount).toFixed(2) > 100) ? 100 : (o.allSubscriptionAmount * 100 / o.expectSaleAmount).toFixed(2);
            }else{
              o.process = 0;
            }
          });

          $scope.isShowHis = false;

          $scope.page = json.page;
        }
      });
    }
    $scope.$broadcast('scroll.infiniteScrollComplete');
  }

  //$scope.doSomething = function(){
  //  if($scope.pShortName){
  //    $scope.isShowHis = true;
  //  }
  //};
  $scope.$watch('pShortName',function(newValue){
    if($scope.pShortName == ''){

        $scope.isShowHis = true;
    }
    if(newValue){
      console.log(newValue);
      $scope.doingSearch($scope.pShortName);
    }

  });

  //兼容不同接口type
  $scope.toDetail = function(p){
    if(p){
      var type = p.type || p.productType;
      var code = p.code || p.productCode;
      if(type == '06'){
        $state.go('product.pevc', {id: code});
      }else if(type == '02' || type == '03' || type == '07'){
        $state.go('product.xtzgdetail', {id: code});
      }else{//默认私募
        $state.go('product.simu', {id: p.fpFundInfoDTO.id});
      }
    }
  }



  $scope.toback = function(){
    $scope.searchList = {};
    $scope.isShowHis = true;
    $scope.pShortName = '';
    $ionicHistory.goBack();
    //$state.go('app');
  };

  $scope.done = function(str){
    if(str){
      $scope.pShortName = str;
    }

    if(!$scope.pShortName){
      return;
    }
    if(hisSearch){
      hisSearch += ','+$scope.pShortName;
    }else{
      hisSearch = $scope.pShortName;
    }

    // $faAPI.product.allSearch({pShortName:$scope.pShortName || ''}).then(function(json){
    //   $scope.allSearchList = json || {};
    //   $scope.isHis = false;
    //   $scope.isMore = false;
    //   if($scope.allSearchList.countXT==0 && $scope.allSearchList.countZG==0 && $scope.allSearchList.countPEVC==0){
    //     $scope.notSearch = true;
    //   }else{
    //     $scope.notSearch = false;
    //   }
    // });



    $faUtil.cookie('hisSearch', hisSearch, {
      path: '/',
      expires: 1296000
    });
  }

})



  .controller('UserCtrl', function($scope, $faUser,$faAPI) {})
  .controller('UserSettingCtrl', function($rootScope,$scope, $state, $ionicActionSheet, $faUser, $faIOSBridge) {

    $scope.logout = function() {

       $ionicActionSheet.show({
           destructiveText: '确定退出',
           titleText: '下次登录依然可以使用本账号',
           cancelText: '取消',
           destructiveButtonClicked: function() {
            $faUser.logout();
            isOpenLogin = false;//用来监听android在登录界面点击返回直接退出
            //$rootScope.isUserLogin = '0';//取消登录状态否则退出第二次登陆后请求不到视频
           }
       });

    };


    $scope.appraise = function() {
      $faIOSBridge.connect(function(bridge) {
        bridge.send('appraise');
      });
    };

    $scope.update = function() {
      $faIOSBridge.connect(function(bridge) {
        bridge.send('update');
      });
    };
  })
///user.js end

  //inform.js start
  .controller('informCtrl', function($scope,$faAPI,$rootScope,$faUser,$state) {
    function getInform(){
      $faAPI.inform.ddtz().then(function(json){
          console.info(json)
          $rootScope.ddzt = json;
          //if(json.jPushShopCount !=undefined && json.jPushShopCount!='' && json.jPushShopCount!=null) {
          //    if(parseInt(json.jPushShopCount)>0) {
          //        $rootScope.isCusvisit = true;
          //    }
          //}
      });
    }
    getInform();
    $scope.goInfoDetail = function(id){
          $faUser.info.isLogin ? $state.go('inform.list',{id:id}) : $rootScope.modal.login(getInform);
    };
    $rootScope.clearPush();

  })
  .controller('cjzxCtrl', function($scope,cjzx,$faShare) {
    $scope.cjzx = cjzx;
    var temp = cjzx.dto.content.replace(/<[^>]+>/g, '').substring(0,100);

    $scope.share = function(){
      var shareData = {
        title:cjzx.dto.title,//标题
        desc:temp,//正文
      }
      $faShare.share(shareData);
    }


  })
  .controller('zxxwCtrl', function($scope,zxxw,$faShare) {

    $scope.zxxw = zxxw;
    var temp = zxxw.list[0].productContent.replace(/<[^>]+>/g, '').substring(0,100);
    $scope.share = function(){
      var shareData = {
        title:zxxw.list[0].productName,//标题
        desc:temp,//正文
      }
      $faShare.share(shareData);
    }

  })
  .controller('jytzCtrl', function($scope,jytz,$faShare) {
    $scope.jytz = jytz;
  })
  .controller('zxggCtrl', function($scope,zxgg,$faShare) {

    $scope.zxgg = zxgg;
    var temp = zxgg.dto.content.replace(/<[^>]+>/g, '').substring(0,100);

    $scope.informShare = function(){

      var shareData = {
        title:zxgg.dto.title,//标题
        desc:temp,//正文
      }
      $faShare.share(shareData);

    }

  })
  .controller('cpxxCtrl', function($scope,cpxx,$faWechat,$faShare,$faUser,$location,$timeout,$ionicNavBarDelegate) {

    $scope.cpxx = cpxx;
    $scope.params = $location.search();
    var user = $faUser;


    if($scope.params.name){
      $scope.uName =decodeURI($scope.params.name);
    }

    if($scope.params.share) {
      $timeout(function() {
        $ionicNavBarDelegate.showBar(false);
      }, 0);
    }
    var shareData = {
      title:cpxx.pricectLike.pName,//标题
      desc:cpxx.pricectLike.content,//正文
    }
    $faShare.wechatShare(shareData);
    //app分享和微信分享
    $scope.share = function(){

      $faShare.share(shareData);

    }

  })
  .controller('informlistCtrl', function($scope,$faAPI,$rootScope,$faUser,$faPlatform,$faIOSBridge,$stateParams) {

    //消息
    if($stateParams.id == 1) {
        $scope.title = '交易通知';
        $scope.listType = 'jytz';
    }else if($stateParams.id == 2) {
      $scope.title = '订阅通知';
      $scope.listType = 'dytz';
    }else if($stateParams.id == 3){
      $scope.title = '公告信息';
      $scope.listType = 'zxgg';
    }else if($stateParams.id == 5){
      $scope.title = '系统消息';
      $scope.listType = 'xitong';
    } else if($stateParams.id == 4){
      $scope.title = '产品信息';
      $scope.listType = 'jytz';
    }else if($stateParams.id == 6){
      $scope.title = '店铺消息';
      $scope.listType = 'shop';
    }

    $scope.jytz_list = [];
    $scope.jytz_page = {
      nextPage:1,
      pageSize:5,
      hasNaxtPage:true
    };

    $scope.loadMoreItems = function(name){
      if(name == 'jytz'){
        if($scope.title == '产品信息'){
          $scope.lType = '09';
        }
        $faAPI.inform.jytz({
          type:$scope.lType,
          faId:$faUser.info.id,
          pageNo:$scope.jytz_page.nextPage,
          pageSize:$scope.jytz_page.pageSize,

        }).then(function(json){


          $scope.jytz_list = $scope.jytz_list.concat(json.list);
          $scope.jytz_page = json.pager;
          $scope.isData = $scope.jytz_list.length;
          $scope.$broadcast('scroll.infiniteScrollComplete');
        });
      }
      if(name == 'dytz'){
        $faAPI.inform.dytz({
          pageNo:$scope.jytz_page.nextPage,
          pageSize:$scope.jytz_page.pageSize

        }).then(function(json){


          $scope.jytz_list = $scope.dytz_list.concat(json.list);
          $scope.jytz_page = json.pager;
          $scope.isData = $scope.jytz_list.length;

          $scope.$broadcast('scroll.infiniteScrollComplete');
        });
      }
      if(name == 'zxgg'){
        $faAPI.inform.zxgg({
          type:8,
          pageNo:$scope.jytz_page.nextPage,
          pageSize:$scope.jytz_page.pageSize,
        }).then(function(json){

          $scope.jytz_list = $scope.jytz_list.concat(json.list);
          $scope.jytz_page = json.pager;
          $scope.isData = $scope.jytz_list.length;
          $scope.$broadcast('scroll.infiniteScrollComplete');
        });
      }
      if(name == 'xitong'){
        $faAPI.inform.xitong({
          pageNo:$scope.jytz_page.nextPage,
          pageSize:$scope.jytz_page.pageSize
        }).then(function(json){

          $scope.jytz_list = $scope.jytz_list.concat(json.list);
          $scope.jytz_page = json.pager;
          $scope.isData = $scope.jytz_list.length;
          console.log($scope.jytz_list);
          $scope.$broadcast('scroll.infiniteScrollComplete');
        });
      }
      if(name == 'shop'){
        $faAPI.inform.shop({
          pageNo:$scope.jytz_page.nextPage,
          pageSize:$scope.jytz_page.pageSize
        }).then(function(json){

          $scope.jytz_list = $scope.jytz_list.concat(json.list);
          $scope.jytz_page = json.pager;
          $scope.isData = $scope.jytz_list.length;
          console.log($scope.jytz_list);
          $scope.$broadcast('scroll.infiniteScrollComplete');
        });
      }

    }
  })
//     .controller('OrderOutUpdataCtrl', function($scope, $stateParams, $faAPI, $faMAP, $faUploader, $timeout, $faPopup, $state, $ionicLoading, $ionicHistory, $faPlatform, $rootScope) {
//     var id = $stateParams.id;
//     $scope.photo = {};
//     $scope.phoStatus = {};
//     $scope.doingUpdate = [];
//
//     $faAPI.product.orderPhos({oId: id}).then(function(json){
//         if(json){
//             $scope.doingUpdate = [];
//             $scope.photo = json.PODList;
//             $scope.phoStatus = json.phoStatus;
//
//             if($scope.photo.length > 0){
//                 $timeout(function() {
//                     angular.forEach($scope.photo, function(o){
//
//                         if(o.oPhoStatus != '02' && o.oPhoStatus != '03'){
//
//                             var t = document.getElementById('up-img' + o.oPhoType);
//                             t.addEventListener('change', function(e){
//                                 doUpload(e, o.oPhoType);
//                             });
//
//                         }
//
//                         $scope.doingUpdate.push({oPhoType: o.oPhoType, oPhoUri: o.oPhoUri});
//                     });
//                 }, 200);
//             }
//         }
//
//     });
//
//     $scope.isShowBigImg = false;
//     $scope.bigImgUrl = '';
//     $scope.showBigImg = function(url){
//         $scope.isShowBigImg = true;
//         $scope.bigImgUrl = baseHref + url;
//     }
//     $scope.hideBigImg = function(){
//         $scope.isShowBigImg = false;
//         $scope.bigImgUrl = '';
//     };
//
//     $scope.done = function() {
//         var phoSta = $scope.phoStatus;
//         if (phoSta == '03') {
//             $faPopup.alert({
//                 title:'审核通过不可提交!'
//             });
//             return;
//         };
//         if (phoSta == '02') {
//             $faPopup.alert({
//                 title:'审核中不可提交!'
//             });
//             return;
//         };
//
//         $faPopup.confirm({
//             title: '确定提交吗？',
//         }, function(res) {
//             if (res) {
//                 // var data = [{oPhoType: "01", oPhoUri: $rootScope.uCardAddress01}];
//                 $faAPI.product.addPhos({'oId':id, 'json': angular.toJson($scope.doingUpdate)}).then(function(res){
//                     $faPopup.alert({
//                         title: '提交成功！'
//                     });
//                     $ionicHistory.goBack();
//                 }, function(res){
//                     $faPopup.alert({
//                         title: '提交失败了'
//                     });
//                 });
//             };
//         });
//     }
//
//     $scope.updataFile = {
//         currentSize: 0,
//         totalSize: 0,
//         percent:0,
//         isShowLoading: false
//     };
//
//     var baseUrl = '';
//
//     if (!$faPlatform.IOSAPP && !$faPlatform.androidAPP) {
//         baseUrl = '/wap/api/fileUpload?fileType=faUserCert';
//     } else {
//         baseUrl = reqUrl + '/wap/api/fileUpload?fileType=faUserCert';
//     }
//
//     function doUpload(e, i){
//         var files = e.target.files;
//         var fileSize = files[0].size;
//
//         if (!$faMAP.regular.image.test(files[0].type)) {
//             $faPopup.alert({
//                 title: '上传的文件格式不对'
//             });
//             $element.removeClass('ng-hide');
//             $element[0].value = '';
//             return;
//         } else if (fileSize > 5242880) {
//             $faPopup.alert({
//                 title: '上传的文件太大了'
//             });
//             $element.removeClass('ng-hide');
//             $element[0].value = '';
//             return;
//         } else if (fileSize < 5120) {
//             $faPopup.alert({
//                 title: '上传的文件太小了'
//             });
//             $element.removeClass('ng-hide');
//             $element[0].value = '';
//             return;
//         }
//
//         $faUploader.removeAll();
//         $faUploader.addFiles(files);
//         $scope.files = $faUploader.getFiles();
//
//         $scope.updataFile.isShowLoading = true;
//         $scope.updataFile.percent = 0;
//
//         $faUploader.startUpload({
//             url: baseUrl,
//             concurrency: 2,
//             onProgress: function(file) {
//                 if(file.loaded <= fileSize){
//                     // console.log('loading' + (file.loaded / fileSize).toFixed(2));
//                     $scope.updataFile.percent = ((file.loaded / fileSize) * 100).toFixed(2);
//                 }else{
//                     $scope.updataFile.percent = 1;
//                     $scope.updataFile.isShowLoading = false;
//                 }
//
//                 $scope.$apply();
//
//                 // $log.info(file.name + '=' + file.humanSize);
//                 // $log.info($scope.files.indexOf(file));
//                 // console.log(file);
//                 // console.log(file.name + '=' + file.humanSize + ',,,' + file.loaded);
//             },
//             onCompleted: function(file, res) {
//                 var res = angular.fromJson(res);
//
//                 if (res.statusCode === '0000') {
//                     var uri = res.attributes.fileUrl;
//                     angular.forEach($scope.doingUpdate, function(o){
//                         if(o.oPhoType == i){
//                             o.oPhoUri = uri;
//                         }
//                     });
//                     angular.forEach($scope.photo, function(p){
//                         if(p.oPhoType == i){
//                             p.oPhoUri = uri;
//                             p.oPhoStatus = '00';
//                         }
//                     });
//                 } else {
//                     $faPopup.alert({
//                         title: $faMAP.statusCode[res.statusCode]
//                     });
//                 }
//                 $scope.$apply();
//             }
//
//         });
//     }
//
// })